﻿using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
using System.Web.UI.WebControls;

namespace ThuChi
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (Session["MaTaiKhoan"] == null)
            {
                mnuAccount.Items[0].Text = "Chào bạn";
                ThuChiSiteMapDataSource.SiteMapProvider = "User";
            }
            else
            {
                TaiKhoan taikhoan = Utilities.GetTaiKhoanById((int)Session["MaTaiKhoan"]);
                if (taikhoan == null)
                {
                    mnuAccount.Items[0].Text = "Chào bạn";
                    ThuChiSiteMapDataSource.SiteMapProvider = "User";
                }
                else
                {
                    mnuAccount.Items[0].Text = "Chào bạn: " + taikhoan.TenDayDu;
                    if(taikhoan.MaQuyen == 1)
                        ThuChiSiteMapDataSource.SiteMapProvider = "Administrator";
                    else if(taikhoan.MaQuyen == 2)
                        ThuChiSiteMapDataSource.SiteMapProvider = "Moderator";
                    else
                        ThuChiSiteMapDataSource.SiteMapProvider = "User";
                }
            }
        }

        protected void mnuAccount_MenuItemClick(object sender, MenuEventArgs e)
        {
            if (e.Item.Text == "Đăng xuất")
            {
                Session["MaTaiKhoan"] = null;
                Response.Redirect("~/Login.aspx");
            }
        }

        protected void MainMenu_MenuItemClick(object sender, MenuEventArgs e)
        {
            if (e.Item.Text == "Đăng xuất")
            {
                Session["MaTaiKhoan"] = null;
                Response.Redirect("~/Login.aspx");
            }
        }
    }
}
